package com.zxy.javaarithmetic.chapter_2_LinkList;

/*
 *  @项目名：  study
 *  @包名：    com.zxy.javaarithmetic.chapter_2_LinkList
 *  @文件名:   LinkListUtils
 *  @创建者:   zhangxy
 *  @创建时间:  2018/12/7 15:47
 *  @描述：    TODO
 */
public class LinkListUtils {

	public static Node getNode(int n){
		Node head = new Node((int) (Math.random()*10+1));
        Node cur = head;
		for (int i = 1; i < n; i++) {
			cur.next = new Node((int) (Math.random()*10+1));
			cur = cur.next;
		}
		return head;
	}

	public static Node getRingNode(int n){
		Node head = new Node((int) (Math.random()*10+1));
		Node cur = head;
		for (int i = 1; i < n; i++) {
			cur.next = new Node((int) (Math.random()*10+1));
			cur = cur.next;
		}
		cur.next = head;
		return head;
	}

	public static void printNode(Node head) {
		if(head == null){
			System.out.println("head node is null");
			return;
		}
		Node cur = head;
		while (cur != null) {
			System.out.print(cur.value + "  ");
			cur = cur.next;
		}
		System.out.println("");
	}

	public static void printRingNode(Node head) {
		if(head == null){
			System.out.println("head node is null");
			return;
		}
		Node cur = head;
		while (cur != null) {
			System.out.print(cur.value + "  ");
			cur = cur.next;
			if(cur == head){
				break;
			}
		}
		System.out.println("");
	}

}
